//
//  ResetPSWViewController.m
//  陶瓷
//
//  Created by 郭天龙 on 15/9/7.
//  Copyright (c) 2015年 王戈. All rights reserved.
//

#import "ModifyPSWViewController.h"

@interface ModifyPSWViewController ()

@property (nonatomic, weak) IBOutlet UITextField *oldPassword;
@property (nonatomic, weak) IBOutlet UITextField *anewPassword;
@property (nonatomic, weak) IBOutlet UITextField *confirmPassword;
@property (nonatomic, weak) IBOutlet UIButton *confirmBtn;
@property (nonatomic, strong) UIButton *cover;
@property (nonatomic, weak) IBOutlet UIView *background;

@end

@implementation ModifyPSWViewController

- (UIButton *)cover {
    if (_cover == nil) {
        _cover = [[UIButton alloc] initWithFrame:self.view.bounds];
        _cover.backgroundColor = [UIColor clearColor];
    }
    return _cover;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationItem setTitle:@"修改密码"];
    
    // Do any additional setup after loading the view from its nib.
    self.anewPassword.secureTextEntry = YES;
    self.confirmPassword.secureTextEntry = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resignTextfield)];
    tap.numberOfTapsRequired = 1;
    [self.background addGestureRecognizer:tap];
    _confirmBtn.layer.cornerRadius = 10;
    
}

- (void)resignTextfield
{
    [self.oldPassword resignFirstResponder];
    [self.anewPassword resignFirstResponder];
    [self.confirmPassword resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnTouchUpInside:(UIButton *)confirmBtn
{
    if (_oldPassword.text.length == 0) {
        [STAlertView st_promptAlertWithMessage:@"请输入旧密码"];
        return;
    }
    if (_anewPassword.text.length == 0) {
        [STAlertView st_promptAlertWithMessage:@"请填入新密码"];
        return;
    }
    if (_confirmPassword.text.length == 0) {
        [STAlertView st_promptAlertWithMessage:@"请填入确认密码"];
        return;
    }
    [SVProgressHUD showWithStatus:@"正在修改 请稍候"];
    [self.view addSubview:self.cover];
    
    [[TCNetworkTool sharedNetTool] changePasswordWithNewPD:self.anewPassword.text andConfirmPassword:self.confirmPassword.text andOldPassword:self.oldPassword.text andSuccessBlocks:^(NSString *successMessage) {
        [self.cover removeFromSuperview];
        [MBHUDHelper showWarningWithText:successMessage];
        [self.navigationController popViewControllerAnimated:YES];
    } andFailureBlocks:^(NSString *failureMessage) {
        [self.cover removeFromSuperview];
        [MBHUDHelper showWarningWithText:failureMessage];
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
